//
// Created by chizuru on 2025/9/2.
//

#pragma once
#include "CameraDevice.h"
#include "TransactionCommandBatchWrite.h"
#include "OperationResult.h"
#include <memory>
#include <string>

class TinyXmlRegisterCLBMap;
class CameraController {
public:

    CameraController(CameraDevice& c, std::shared_ptr<TinyXmlRegisterCLBMap> rm, RetryPolicy rp = {}) ;

    virtual ~CameraController() = default;

    OperationResult setRegister(const std::string &cat, const std::string &name, uint32_t value, bool isRollback = false);

    OperationResult getRegister(const std::string &cat, const std::string &name, std::optional<uint32_t> &out);

    OperationResult applyTransactionWrite(const std::vector <std::tuple<std::string, std::string, uint32_t>> &ops) ;

    OperationResult applyTransactionRead(const std::vector <std::pair<std::string, std::string>> &ops, std::vector<std::optional<uint32_t>>& out);

private:
    CameraDevice& comm;
    std::shared_ptr<TinyXmlRegisterCLBMap> regMap;
    RetryPolicy rp;
};

